<?php 
/******************************************************************************
 *                                                                            *
 * Copyright (c) 1999-2011 Blackboard Inc., All Rights Reserved.                *
 *                                                                            *
 * COPYRIGHT:                                                                 *
 *      This software is the property of Blackboard Inc.                       *
 *      You can redistribute it and/or modify it under the terms of           *
 *      the GNU General Public License as published by the                    *
 *      Free Software Foundation.                                             *
 *                                                                            *
 * WARRANTIES:                                                                *
 *      This software is distributed in the hope that it will be useful,      *
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *      GNU General Public License for more details.                          *
 *                                                                            *
 *      You should have received a copy of the GNU General Public License     *
 *      along with the Wimba Probto Moodle Integration;                      *
 *      if not, write to the Free Software Foundation, Inc.,                  *
 *      51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA                *
 *                                                                            *
 * Author: Jonathan Abourbih
 *                                                                            *
 * Date: 14 April 2011
 *                                                                            *
 ******************************************************************************/
require_once('../../config.php');
require_once("lib.php");

$id = required_param('id', PARAM_INT);   // course

$PAGE->set_url('/mod/pronto/index.php', array('id'=>$id));

if (! $course = $DB->get_record("course", array("id" => $id))) {
  error("Course ID is incorrect");
}

require_login($course->id);

pronto_audit_log(PRONTO_VIEW_ALL, "index.php?id=$course->id");

$coursecontext = context_course::instance($course->id);

$PAGE->set_context($coursecontext);
$PAGE->set_url('/mod/pronto/index.php?id=' . $course->id);
$PAGE->set_heading($course->shortname . ":" . get_string("modulenameplural", "pronto"));
$PAGE->set_pagelayout('incourse');
$PAGE->set_course($course);

echo $OUTPUT->header();
echo $OUTPUT->box_start();

if (! $prontos = get_all_instances_in_course("pronto", $course)) {
  notice(get_string("noprontoinstances", "pronto"), "../../course/view.php?id=$course->id");
die;
}

$timenow = time();
$strname  = get_string("name");
$strweek  = get_string("week");
$strtopic  = get_string("topic");

$indexTable = new html_table();
$indexTable->tablealign = 'center';
if ($course->format == "weeks") {
   $indexTable->head  = array ($strweek, $strname);
   $indexTable->align = array ("center", "left");
} else if ($course->format == "topics") {
   $indexTable->head  = array ($strtopic, $strname);
   $indexTable->align = array ("center", "left", "left", "left");
} else {
   $indexTable->head  = array ($strname);
   $indexTable->align = array ("left", "left", "left");
}

foreach ($prontos as $pronto) {
  if (!$pronto->visible) {
    //Show dimmed if the mod is hidden
    $link = "<a class=\"dimmed\" href=\"view.php?id=$pronto->coursemodule\">$pronto->name</a>";
  } else {
    //Show normal if the mod is visible
    $link = "<a href=\"view.php?id=$pronto->coursemodule\">$pronto->name</a>";
  }

  if ($course->format == "weeks" or $course->format == "topics") {
     $indexTable->data[] = array ($pronto->section, $link);
  } else {
     $indexTable->data[] = array ($link);
  }
}

echo "<br />";

echo html_writer::table($indexTable);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
